import Vue from 'vue';

function Confirm(properties) {
	const _props = Object.assign({
		okText: undefined,
		cancelText: undefined,
		title: '操作提示',
		width: 300,
		content: '',
		onOk: function() {
			
		},
		onCancel: function() {
			
		}
	}, properties);
	const Instance = new Vue({
    	data: Object.assign(_props, {
    		show: false
    	}),
    	mounted() {
    		this.show = true;
    	},
    	methods: {
    		ok() {
    			this.remove();
    			_props.onOk();
    		},
    		cancel() {
    			_props.onCancel();
    			this.remove();
    		},
    		remove () {
                setTimeout(() => {
                    this.destroy();
                }, 300);
            },
            destroy () {
                this.$destroy();
                document.body.removeChild(this.$el);
            }
    	},
    	template: '<wsModal v-model="show" :ok-text="okText" :cancel-text="cancelText" :title="title" :width="width" @on-ok="ok" @on-cancel="cancel"><p v-text="content"></p></wsModal>'
  	});
  	var component = Instance.$mount()
	document.body.appendChild(component.$el);
};
//
//
//
////const modal = Instance.$children[0];
////
//注册VUE全局对象
Vue.prototype.$confirm = Confirm;
